package com.jar.exercise.集合和数据结构.ArrayList线程不安全问题;

import lombok.NonNull;

import java.util.ArrayList;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 *  <div  style="border:2px solid none;margin:20px;padding:15px;font-size:24px;text-align:center;color:aqua;">
 *
 *
 *
 *  </div>
 * @author v_zhangshun01
 * @date 2021/10/9 2:49 下午
 */
public class App {

    static ExecutorService executorService = new ThreadPoolExecutor(
            10,
            10,
            100L,
            TimeUnit.MICROSECONDS,
            new ArrayBlockingQueue<>(10),
            Thread::new,
            new ThreadPoolExecutor.AbortPolicy()
    );

    public static void main(String[] args) {

        ArrayList<String> arrayList = new ArrayList<>();

        for (int i = 0; i < 100; i++) {
            int finalI = i;
            executorService.execute(()-> arrayList.add(finalI + ""));
        }

        System.out.println(arrayList.size());

    }

}
